#include "lvgl/lvgl.h"
/* 添加 fb 支持 */
#include "lv_drivers/display/drmdev.h"
#include "lv_examples/lv_examples.h"
#include <unistd.h>
#include <stdio.h>
#include "evdev.h"
static lv_disp_buf_t disp_buf;
static lv_color_t buf1[LV_HOR_RES_MAX * LV_VER_RES_MAX];
static lv_color_t buf2[LV_HOR_RES_MAX * LV_VER_RES_MAX];
int main(void)
{
    /*LittlevGL init*/
    lv_init();

    /*Linux frame buffer device init*/
    drm_init();
    lv_disp_buf_init(&disp_buf, buf1, buf2, LV_HOR_RES_MAX * LV_VER_RES_MAX);
    /*Add a display the LittlevGL sing the frame buffer driver*/
    lv_disp_drv_t disp_drv;
    lv_disp_drv_init(&disp_drv);
    fprintf(stderr,"init \r\n");
    disp_drv.flush_cb = drm_flush;      /*It flushes the internal graphical buffer to the frame buffer*/
    disp_drv.wait_cb = drm_wait_vsync;
    disp_drv.buffer = &disp_buf;
    lv_disp_drv_register(&disp_drv);
    fprintf(stderr,"init register\r\n");

    //input dev
    lv_indev_drv_t indev_drv;
    lv_indev_drv_init(&indev_drv);
    evdev_init();
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    indev_drv.read_cb = evdev_read;
    lv_indev_drv_register(&indev_drv);

    /* 选择示例启动 */
    //lv_demo_benchmark();
    //lv_demo_widgets();
    //lv_demo_stress();
    //lv_ex_get_started_2();
    lv_demo_printer();
    fprintf(stderr,"init ok...\r\n");
    /*Handle LitlevGL tasks (tickless mode)*/
    while(1) {
        lv_tick_inc(3);
        lv_task_handler();
        usleep(3000);
    }

    return 0;
}
